package com.xiaohu.myspace.action;

import java.util.Date;
import java.util.List;

import com.xiaohu.myspace.buiness.buinessinterface.MessageInfoInterface;
import com.xiaohu.myspace.database.entity.MessageInfo;
import com.xiaohu.myspace.vo.MessageInfoVo;

public class MessageInfoAction extends BaseAction {

	private static final long serialVersionUID = 8169132436889126813L;

	private MessageInfoInterface messageInfoInterface;

	private int type;
	private int pageNum = 1;
	private String returnData;
	private MessageInfo messageInfo;

	public String getReturnData() {
		return returnData;
	}

	public void setReturnData(String returnData) {
		this.returnData = returnData;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public MessageInfo getMessageInfo() {
		return messageInfo;
	}

	public void setMessageInfo(MessageInfo messageInfo) {
		this.messageInfo = messageInfo;
	}

	public MessageInfoInterface getMessageInfoInterface() {
		return messageInfoInterface;
	}

	public void setMessageInfoInterface(
			MessageInfoInterface messageInfoInterface) {
		this.messageInfoInterface = messageInfoInterface;
	}

	public String getMessageInfoWithType() {
		if (0 == type) {
			return ERROR;
		}
		List<MessageInfoVo> listData = messageInfoInterface
				.getMessageInfoWithHQL(type, pageNum);
		returnData = initReturnData(SUCCESSCODE, listData);
		if (null != listData) {
			System.out.println(returnData);
			return SUCCESS;
		}
		return ERROR;
	}

	public String addMessageInfo() {
		if (null == messageInfo) {
			return ERROR;
		}
		Integer userId=messageInfo.getMessageEditor();
		if (null==userId) {
			messageInfo.setMessageEditor(1);
		}
		messageInfo.setMessageCommentCount(0);
		messageInfo.setMessageDate(new Date());
		messageInfo.setMessageUpDown("0,0");
		boolean flag = messageInfoInterface.addMessage(messageInfo);
		returnData = initReturnData(SUCCESSCODE, messageInfo);
		if (flag) {
			System.out.println(returnData);
			return SUCCESS;
		}

		return ERROR;
	}

}
